/*
 * @Author: Drc
 * @Date: 2020-12-14 16:41:12
 * @LastEditTime: 2021-11-05 15:09:18
 * @LastEditors: Drc
 */
import {init, Models, RematchRootState} from '@rematch/core'
import createRematchPersist from '@rematch/persist'
import storage from '@react-native-community/async-storage'
import models from './models'

export type RootState = RematchRootState<typeof models>
export interface RootModel extends Models<RootModel> {
  user: typeof models.user
  utils: typeof models.utils
  global: typeof models.global
}

const persistPlugin = createRematchPersist({
  key: 'root',
  whitelist: ['user'],
  storage,
  throttle: 0,
  version: 1,
  timeout: 1000,
})

const store = init({
  models,
  plugins: [persistPlugin],
})

export default store
